package com.yc.jpa.dao;

import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.yc.entity.Student;

public interface StudentJpqlDao extends Repository<Student, Integer> {

	@Query(value = "select d from Student d where d.name=:name")
	List<Student> getStudentByName(@Param("name")String name);
	
	/**
	 * 两个注解不能少：
	 * @Modifying
	 * @Transactional
	 * @param name
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from Student d where d.name=:name")
	void deleteByName(@Param("name")String name);
	
	/**
	 * 删除、更新 两个注解不能少：
	 * @Modifying
	 * @Transactional
	 */
	@Transactional
	@Modifying
	@Query(value = "update Student d set d.name=:name where d.id=:id")
	void updateByName(@Param("id")Integer id, @Param("name")String name);
	
	
	@Query(value = "select d from Student d where d.name=:name")
	List<Student> pageStudentByName(@Param("name")String name, Pageable pageable);
	
}
